#include "dbenv.hxx"
#include "dbenv_impl.hxx"
    
DbEnv::DbEnv(const std::string& home, const std::string& logpath, const
        std::string& logmsgFile, uint32_t lgBufSize)
:   m_envImpl(NULL), 
    m_home(home), 
    m_logdir(logpath), 
    m_logmsgFile(logmsgFile),
    m_lgBufSize(lgBufSize) {

}

DbEnv::~DbEnv() {

    if(m_envImpl) { 
        close();
    }
}

DbStatus DbEnv::open(uint32_t flag) {
    
    m_envImpl = new DbEnvImpl(m_home, m_logdir, m_logmsgFile, m_lgBufSize);

    return m_envImpl->open(flag);
}

DbStatus DbEnv::close() {

    DbStatus ret;
    
    if(m_envImpl == NULL) return ret;

    ret = m_envImpl->close();
    if(!ret.isok()) return ret;

    delete m_envImpl;
    m_envImpl = NULL;

    return ret;
}

DbStatus DbEnv::start() {

    return  m_envImpl->start();
}

DbStatus DbEnv::sync() {

   return  m_envImpl->sync();
}

DbStatus DbEnv::flushlog() {
    
    return m_envImpl->flushlog();
}

std::string DbEnv::getHomepath() {

    return m_home;
}


std::string DbEnv::getLogpath() {

    return m_logdir;
}

void DbEnv::setLogBufferSize(uint32_t size) {

    m_lgBufSize = size;
    m_envImpl->setLogBufferSize(size);
}

uint32_t DbEnv::getLogBufferSize() {

    return m_lgBufSize;
}

void DbEnv::startCompact() {
    
    m_envImpl->startCompact();
}


void DbEnv::stopCompact() {

    m_envImpl->stopCompact(false);
}


